﻿<div class="easyui-layout" id="Layout_dm_thong_tin_Cap_quang">
    <div id="pannel_list_mang_vt_find_cap_quang" data-options="region:'west', collapsible:false" title="MẠNG VT" style="width: 300px; padding: 10px">

         <div id="TreeGird_dm_dvi_toql_cap_quang"></div>

    </div>
    <div id="pannel_list_cap_quang" data-options="region:'center'" style="padding:5px; position:relative" title="Danh sách cáp quang">
        <div id="list_cap_quang_TableContainer"></div>
    </div>
</div>


<script type="text/javascript">

    var matoqlCurrently_cap_quang = "";
    var madonviCurrently_Cap_quang = "";
    var maiTypeComGirdCurrntly_cap_quang = "all";

    $(document).ready(function () {



        $("#Layout_dm_thong_tin_Cap_quang").css('width', $(window).width() - 5);
        $("#Layout_dm_thong_tin_Cap_quang").height($(window).height() - 100);
        $('#list_cap_quang_TableContainer').height($(window).height() - 180);
        $('#list_cap_quang_TableContainer').width($("#pannel_list_cap_quang").width() - 315);
        
        $("#Layout_dm_thong_tin_Cap_quang").mask("Dữ liệu đang tải về ");
        
        $("#TreeGird_dm_dvi_toql_cap_quang").treegrid({

            url: _nameSubDomain + "/TThietbi/listDVTOByTramFromDauNoi",
            idField: "id",
            treeField: "text",
            lines: true,
            animate: true,
            collapsible: true,
            fitColumns: true,
            width: $("#pannel_list_mang_vt_find_cap_quang").width() - 30,
            height: $(window).height() - 200,
            columns: [[
                { field: 'id', resizable: false, hidden: true },
                { field: 'text', resizable: false, title: 'ĐƠN VỊ', width : 110 }
            ]],
            onSelect: function (row) {

                $("#pannel_list_cap_quang").mask("Dữ liệu đang xử lý");

                $('#list_cap_quang_TableContainer').jtable('load', { donvi: row.Idparent, toql: row.id, type: row.type });

                maiTypeComGirdCurrntly_cap_quang = row.type;

                setTimeout(function () {
                    if (row.type == "dv") {
                        madonviCurrently_Cap_quang = row.id; matoqlCurrently_cap_quang = "";
                    }
                    else if (row.type == "toql") {
                        madonviCurrently_Cap_quang = row.Idparent; matoqlCurrently_cap_quang = row.id;
                    }
                    else {
                        madonviCurrently_Cap_quang = row.Idparent_parent; matoqlCurrently_cap_quang = row.Idparent;
                    }



                }, 200);

                setTimeout(function () { $("#pannel_list_cap_quang").unmask(); }, 2000);

            }
        });


        $('#list_cap_quang_TableContainer').jtable({

            title: 'DS CÁP QUANG',
            openChildAsAccordion: true,
            actions: {
                listAction: _nameSubDomain + '/TCapquang/ListCapQuang?donvi=&toql=&type=null',
                deleteAction: function (postData) {
                    console.log("deleting from custom function...");
                    return $.Deferred(function ($dfd) {

                        $("#pannel_list_cap_quang").mask("Dữ liệu đang được xóa");

                        $.ajax({
                            url: _nameSubDomain + '/TCapquang/DeleteLTB',
                            type: 'POST',
                            dataType: 'json',
                            data: postData,
                            success: function (data) {

                                $dfd.resolve(data);
                                setTimeout(function () { $("#pannel_list_cap_quang").unmask(); }, 600);

                            },
                            error: function () {
                                $dfd.reject();
                            }
                        });
                    });
                }


            },
            toolbar: {
                hoverAnimation: true, //Enable/disable small animation on mouse hover to a toolbar item.
                hoverAnimationDuration: 60, //Duration of the hover animation.
                hoverAnimationEasing: undefined, //Easing of the hover animation. Uses jQuery's default animation ('swing') if set to undefined.
                items: [
                    {
                        icon: _nameSubDomain + '/Content/images/add.png',
                        text: 'Thêm mới cáp quang',
                        click: function () {
                            _openWinDowAddCapQuang();
                        }
                    }
                ] //Array of your custom toolbar items.
            },
            fields: {
                ID: {
                    key: true,
                    edit: false,
                    create: false,
                    //list:false,
                    width: '3%',
                    display: function (tbData) {
                        var $img = $('<img src="' + _nameSubDomain + '/Content/images/1356080636_cog.png" style="cursor:pointer;" title="Xem thông tin sợi quang" />');
                        //Open child table when user clicks the image
                        $img.click(function () {
                            $img.closest('tr').mask("Đang load dữ liệu");
                            $('#list_cap_quang_TableContainer').jtable('openChildTable',
                                   $img.closest('tr'), //Parent row
                                   {
                                       title: 'Sợi quang của cáp quang ' + tbData.record.TEN,
                                       //toolbar: {
                                       //    hoverAnimation: true, //Enable/disable small animation on mouse hover to a toolbar item.
                                       //    hoverAnimationDuration: 60, //Duration of the hover animation.
                                       //    hoverAnimationEasing: undefined, //Easing of the hover animation. Uses jQuery's default animation ('swing') if set to undefined.
                                       //    items: [
                                       //        {
                                       //            icon: _nameSubDomain + '/Content/images/add.png',
                                       //            text: 'Thêm mới cấu hình thiết bị',
                                       //            click: function () {
                                       //                //_openWinDowAddCauHinhTB(tbData.record.ID, tbData.record.DMTHIETBI, tbData.record.TEN);
                                       //            }
                                       //        }
                                       //    ] //Array of your custom toolbar items.
                                       //},
                                       actions: {
                                           listAction: _nameSubDomain + '/TCapquang/ListSoiQuangByCapQuang?capquangId=' + tbData.record.ID,
                                           updateAction: _nameSubDomain + '/TCapquang/UpdateSoiQuangByCapQuang',
                                           //deleteAction: _nameSubDomain + '/TThietbi/DeleteCauHinhTB'
                                       },
                                       fields: {
                                           ID: {
                                               key: true,
                                               //create: false,
                                               //edit: false,
                                               list: false,
                                               //title: 'Mã MVT',

                                           },
                                           SOI: {
                                               title: 'Sợi',
                                               width: '20%'
                                           },
                                           ODFID: {
                                               title: 'Odf',
                                               width: '30%',
                                               edit: false,
                                               display: function (data) {
                                                   return Get_Odf_ById_Get_Ten(data.record.ODFID);
                                               }
                                               //options: function (data) { _nameSubDomain + '/TCapquang/ListODfBySiteIdJtable?siteId=' + data.record.ODFID; }
                                           },
                                           TRANGTHAI: {
                                               title: 'Sử dụng',
                                               width: '20%',
                                               //display: function (data) {
                                               //    return getTrangthaibyId(data.record.TRANGTHAI).TRANGTHAI1;
                                               //},
                                               options: _nameSubDomain + '/TThietbi/ListTrangThai'
                                           },
                                           GHICHU: {
                                               title: 'Ghi chú',
                                               width: '30%',

                                           },
                                           //UPDATE: {
                                           //    display: function (data) {
                                           //        return '<button title="Edit Record" onclick="return _UpdateCauHinhTB(' + data.record.ID + ', \'' + tbData.record.DMTHIETBI + '\', \'' + tbData.record.TEN + '\')" class="jtable-command-button jtable-edit-command-button"><span></span></button>';
                                           //    },
                                           //    create: false,
                                           //    edit: false,
                                           //    width: '3%'
                                           //},
                                       },
                                       recordsLoaded: function (event, data) {

                                           setTimeout(function () {
                                               $img.closest('tr').unmask();
                                           }, 400);

                                       }
                                   },

                                   function (data) { //opened handler
                                       setTimeout(function () {
                                           data.childTable.jtable('load');
                                          
                                       }, 200);
                                   });
                            
                        });
                        //Return image to show on the person row
                        return $img;
                    }
                },
                MA: {
                    title: 'Mã cáp',
                    width: '10%'
                },
                TEN: {
                    title: 'Tên cáp',
                    width: '20%'
                },
                ODF1: {
                    title: 'Trạm đầu gần',
                    width: '10%',
                    display: function (data) {
                        return '<p class="view_odf_cap_quang" onclick="return view_odf_cap_quang(' + data.record.ODF1 + ')">' + Get_Odf_ById(data.record.ODF1).TEN + '</p>';
                    }
                },
                ODF2: {
                    title: 'Trạm đầu xa',
                    width: '10%',
                    display: function (data) {
                        return '<p class="view_odf_cap_quang" onclick="return view_odf_cap_quang(' + data.record.ODF2 + ')">' + Get_Odf_ById(data.record.ODF2).TEN + '</p>';
                    }
                },
                CHIEUDAI: {
                    title: 'C.Dài',
                    width: '10%',
                    
                },
                DUNGLUONG: {
                    title: 'D.Lượng',
                    width: '10%',
                    
                },
                //LOAISOI: {
                //    title: 'L.Sợ',
                //    width: '15%',
                //    display: function (data) {
                //        return Get_loaiso_ById(data.record.LOAISOI).TEN;
                //    }
                    
                //},
                //LOAIPHA: {
                //    title: 'L.Pha',
                //    width: '10%',
                //    display: function (data) {
                //        return GetLoaiPhaById(data.record.LOAIPHA).TEN;
                //    }
                //},
                LAPDAT: {
                    title: 'Lắp đặt',
                    width: '10%',
                    display: function (data) {
                        return Get_loailapdat_ById(data.record.LAPDAT).TEN;
                    }
                },
                UPDATE: {
                    display: function (data) {
                        return '<button title="Edit Record" onclick="return _UpdateCapQuang(' + data.record.ID + ')" class="jtable-command-button jtable-edit-command-button"><span></span></button>';
                    },
                    create: false,
                    edit: false,
                    width: '3%'
                },
               

            },
            //Initialize validation logic when a form is created
            formCreated: function (event, data) {
                //data.form.find('input[name="TEN"]').addClass('validate[required]');
                data.form.validationEngine();
            },

        });

        $('#list_cap_quang_TableContainer').jtable('load');
        
        setTimeout(function () { $("#Layout_dm_thong_tin_Cap_quang").unmask(""); }, 1000);

    });


    

    function _openWinDowAddCapQuang()
    {
        loadwindowOnContent(_nameSubDomain + "/TCapquang/AddCapQuang?_donviql=" + madonviCurrently_Cap_quang + "&_toql=" + matoqlCurrently_cap_quang, "window_addupdate_add_cap_quang", "Thêm thông tin cáp quang", 750, 550);
    }

    function _UpdateCapQuang(id) {

        loadwindowOnContent(_nameSubDomain + "/TCapquang/updateCapQuang?Id=" + id, "window_addupdate_add_cap_quang", "Cập nhật thông tin cáp quang", 750, 550);

    }


    function view_odf_cap_quang(odfId) {

        loadwindowOnContent(_nameSubDomain + "/TCapquang/ViewSoiQuangOnOdf?Id=" + odfId, "window_view_soi_quang_cap_quang", "Thông tin odf sợi quang ", 750, 550);

    }
    


</script>